<?php
namespace app\admin\model;

use think\Model;

class RolePermission extends Model
{
    public function getPermissionIds($role_ids){
        $permission = db('rolePermission')->where(['role_id'=>['in',$role_ids]])->select();
        $permission_list = [];
        foreach ($permission as $k => $v) {
            if(!in_array($v['permission_id'],$permission_list)){
                $permission_list[] = $v['permission_id'];
            }
        }
        $permission_list = implode(',',$permission_list);
        return $permission_list;
    }
    public function deletePermission($role_id){
        db('rolePermission')->where("role_id='$role_id'")->delete();
    }

    public function addPermission($role_id,$permission_ids){
        foreach ($permission_ids as $key => $value) {
            db('rolePermission')->insert(['role_id'=>$role_id,'permission_id'=>$value]);
        }
    }
}